package com.wtgroup.demo.mianshi.jvm;

import java.util.LinkedList;
import java.util.List;

/**
 * @author nisus
 * @version 0.1
 * @since 2023/5/30 16:10
 */
public class D_Memory {

    /**
     * java -Xms10M -Xmx10M
     * */

    public static void main(String[] args) throws InterruptedException {
        System.out.println("HelloGC!");
        System.out.println(Thread.currentThread());
        List<byte[]> list = new LinkedList<byte[]>();
        for(;;) {
            byte[] b = new byte[1024*1024]; // 1M
            list.add(b);

            // 一半几率回收掉
            if (Math.random() > 0.5) {
                list.remove(list.size() - 1);
            }
            Thread.sleep(100);
        }
    }

}
